package com.emser.unc.server.domain;

import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class CustomerIndex {
		@PrimaryKey
		@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
		private Key key;
		
		@Persistent
		private Set<String> userNameSellers;
		
		public CustomerIndex(String sellerKey, Key key) {
			this.userNameSellers = new HashSet<String>();
			this.userNameSellers.add(sellerKey);
			this.key= key;
		}
		
		public CustomerIndex(String sellerKey, Long customerID) {
			this.userNameSellers = new HashSet<String>();
			this.userNameSellers.add(sellerKey);
			KeyFactory.Builder keyBuilder =
			new KeyFactory.Builder(Customer.class.getSimpleName(), customerID);
			keyBuilder.addChild(CustomerIndex.class.getSimpleName(), customerID);
			Key ckey = keyBuilder.getKey();
			this.key= ckey;
		}
	
		public void setKey(Key key) {
			this.key = key;
		}
		
		public void addSellerKey(String sellerKey){
			this.userNameSellers.add(sellerKey);
		}

		public Key getKey() {
			return key;
		}

		public Set<String> getUserNameSellers() {
			return userNameSellers;
		}
}
